import 'package:cached_network_image/cached_network_image.dart';
/**
 * 发票页面
 * author wim
 */
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:panda/base/Constant.dart';

class MyReceiptPage extends StatefulWidget {
  MyReceiptPage({Key key}) : super(key: key);

  @override
  _MyReceiptPageState createState() => _MyReceiptPageState();
}

class _MyReceiptPageState extends State<MyReceiptPage> {
  EasyRefreshController _controller = new EasyRefreshController();
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(
          "发票管理",
          style: TextStyle(
              fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
              color: Colors.black),
        ),
        elevation: 0.2,
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        centerTitle: true,
        iconTheme: new IconThemeData(color: Colors.black),
      ),
      body: new Column(
        children: <Widget>[
          Container(
            width: double.infinity,
            padding: EdgeInsets.fromLTRB(
                ScreenUtil.getInstance().setWidth(DP_30),
                ScreenUtil.getInstance().setWidth(DP_20),
                ScreenUtil.getInstance().setWidth(DP_30),
                ScreenUtil.getInstance().setWidth(DP_20)),
            color: white,
            child: new GestureDetector(
              child: Container(
                decoration: BoxDecoration(
                    color: Color.fromARGB(255, 245, 245, 245),
                    borderRadius: BorderRadius.circular(80.0)),
                child: TextField(
                  cursorColor: mainColor,
                  maxLines: 1,
                  textAlign: TextAlign.center,
                  keyboardAppearance: Brightness.light,
                  decoration: new InputDecoration(
                      hintText: "订单名称/订单号/手机号",
                      border: InputBorder.none,
                      hintStyle: TextStyle(
                          color: Colors.black45,
                          fontSize: ScreenUtil.getInstance()
                              .setSp(NORMAL_FONT_SIZE))),
                ),
              ),
              onTap: () {
                print("搜索页面跳转");
              },
            ),
          ),
          Expanded(
            child: EasyRefresh(
              enableControlFinishLoad: true,
              controller: _controller,
              enableControlFinishRefresh: true,
              onLoad: () {},
              onRefresh: () {},
              child: ListView.builder(
                itemBuilder: (BuildContext context, int index) {
                  return renderRow(context, index);
                },
              ),
            ),
          )
        ],
      ),
    );
  }

  renderRow(BuildContext context, int index) {
    return Container(
      padding: EdgeInsets.all(ScreenUtil.getInstance().setHeight(DP_20)),
      margin: EdgeInsets.fromLTRB(
          ScreenUtil.getInstance().setHeight(DP_20),
          ScreenUtil.getInstance().setHeight(DP_20),
          ScreenUtil.getInstance().setHeight(DP_20),
          0),
      decoration: BoxDecoration(
          color: white,
          borderRadius:
              BorderRadius.circular(ScreenUtil.getInstance().setHeight(DP_10))),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text('订单编号：2934854756456354',
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                  fontSize: ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE),
                  color: Colors.black87)),
          Container(
            height: ScreenUtil.getInstance().setHeight(DP_15),
          ),
          new Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.start,
            children: <Widget>[
              ClipRRect(
                borderRadius: BorderRadius.circular(5),
                child: CachedNetworkImage(
                imageUrl:
                    'https://img14.360buyimg.com/n0/jfs/t1/42163/17/16172/246472/5d8dd42cE12fa785a/efbd7ce9dbaac1c1.jpg',
                    width: ScreenUtil.getInstance().setHeight(DP_120),
                    fit: BoxFit.fill,
                    height: ScreenUtil.getInstance().setHeight(DP_120)),
              ),
              Container(
                width: ScreenUtil.getInstance().setHeight(DP_15),
              ),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text('五星酒厂老酒纯粮原浆茅台镇酱香型白酒53度纯粮食老酒500ML*1瓶装',
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                            height: 1.5,
                            fontSize: ScreenUtil.getInstance()
                                .setSp(NORMAL_FONT_SIZE),
                            color: Colors.black87)),
                    Container(
                      height: ScreenUtil.getInstance().setHeight(DP_10),
                    ),
                    Text('礼盒装 500ml',
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                            fontSize:
                                ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE),
                            color: Colors.black38)),
                    Container(
                      height: ScreenUtil.getInstance().setHeight(DP_10),
                    ),
                  ],
                ),
              ),
              Text(MONEY + '168.89',
                  maxLines: 1,
                  style: TextStyle(
                      fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE),
                      color: mainColor)),
            ],
          ),
          Row(
            children: <Widget>[
              Expanded(
                child: Text(''),
              ),
              new Container(
                height: ScreenUtil.getInstance().setHeight(DP_50),
                decoration: new BoxDecoration(
                    border: Border.all(color: mainColor, width: 1),
                    borderRadius: BorderRadius.circular(
                        ScreenUtil.getInstance().setHeight(DP_50))),
                padding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0, 0.0),
                child: new FlatButton(
                  child: new Padding(
                    padding: EdgeInsets.all(0.0),
                    child: new Text(
                      "发票详情",
                      style: new TextStyle(
                          color: mainColor,
                          fontSize:
                              ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE)),
                    ),
                  ),
                  onPressed: () {},
                ),
              )
            ],
          )
        ],
      ),
    );
  }
}
